package com.itehima.Topic3;

import javax.crypto.spec.PSource;
import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Scanner;

//请输入“您的生日”，格式：yyyy-MM-dd，使用程序计算您已经来到这个世界多少天了。
//
//        **提示:**
//
//        本题利用JDK8中的LocalDate加DateTimeFormatter和Period即可实现;
public class Test3 {
    public static void main(String[] args) {
        System.out.println("请输入“您的生日”，格式：yyyy-MM-dd");
        Scanner scanner =new Scanner(System.in);
        String birthday = scanner.next();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate localDate = LocalDate.parse(birthday,dateTimeFormatter );
        Period period = Period.between(localDate, LocalDate.now());
        System.out.println(localDate);
//        System.out.println(LocalDate.now());
        int days = period.getDays();    //获取天
        int months = period.getMonths();  //
        int years = period.getYears();
//        System.out.println(period.getDays());   //天
//        System.out.println(period.getMonths());   //月
//        System.out.println(period.getYears());   //年
        System.out.println("您已经活了：" + years + "年" + (months < 10 ?"零":"")+ months+"月"+(days < 10 ?"零":"")+days+"天了！");



    }
}
